import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { CloudBg } from "../consumeCount/CloudBg";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ItemsBox } from "../common/item/ItemsBox";
import { RechargeProgressBar } from "../loginNotice/OpenRecharge/RechargeProgressBar";
import { GlobalSkin } from "../../../component/skin/GlobalSkin";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { EntityInfo } from "../../scene/player/info/EntityInfo";
import { TBoss } from "../../../../Message/Db/Tables/TBoss";
import { BossRule } from "../../rules/BossRule";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { Tooltip } from "../common/tooltip/Tooltip";
import { PlantFlowerBlessCache } from "./PlantFlowerBlessCache";
import { PlantFlowerConfig } from "../../resource/PlantFlowerConfig";
import { GameConst } from "../../../component/gconst/GameConst";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { TimeButton } from "../common/button/TimeButton";
import { FireTip } from "../common/item/FireTip";
//class PlantFlowerBlessWindow
    
    export  class PlantFlowerBlessWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(375, 265);
            this.titleHeight = 25;
            this.title = Language.getString(69811);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createFlowerBg(18, 38, 339, 215, this);
            ObjCreate.createBg(40, 95, 295, 55, this, ImagesConst.WindowCenterC);
            ObjCreate.createBg(40, 100, 295, 45, this, ImagesConst.RemainningTimeBg);
            var loc1=new CloudBg(283);
            loc1.x = 40;
            loc1.y = 60;
            addChild(loc1);
            var loc2=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6);
            loc2.size = 14;
            loc2.bold = true;
            this._nameLabel = ObjCreate.createGTextField("", 20, 50, 335, 20, this, loc2);
            this._blessLable = ObjCreate.createGTextField(Language.getString(69813), 30, 168, 200, 20, this);
            this._itemsList = new ItemsBox();
            this._itemsList.x = 65;
            this._itemsList.y = 106;
            this.addChild(this._itemsList);
            this._progressBar = new RechargeProgressBar();
            this._progressBar.move(90, 160);
            this._progressBar.progressBarClass = ImagesConst.ProgressInner;
            this._progressBar.isHaveProgressPoint(true);
            this._progressBar.setValue(0, 100);
            this._progressBar.setBgSize(255, 36);
            addChild(this._progressBar);
            this._operBtn = ObjCreate.createTimeButton("", 145, 200, 85, 28, this, GlobalSkin.ButtonSpecial);
            this._operBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._tip = ObjCreate.createFireTip(HTMLUtil.addColor(Language.getString(69816), "#FFFF00"), 102, 225, this, true);
            return;
        }

        public updateFlowerInfo(arg1: EntityInfo, arg2: TBoss): void
        {
            var loc1=0;
            this._info = arg1;
            this._bossInfo = arg2;
            this._isFlower = BossRule.isPlantBossFlower(arg2);
            this._isMine = arg1.isSelf;
            this._canGet = arg1.entityInfo.mana == 0;
            if (this._isFlower) 
            {
                this._nameLabel.htmlText = Language.getStringByParam(69812, arg1.entityInfo.guildName, arg1.entityInfo.name);
                this._blessLable.text = Language.getString(69813);
            }
            else 
            {
                this._nameLabel.htmlText = Language.getStringByParam(69827, arg1.entityInfo.guildName, arg1.entityInfo.name);
                this._blessLable.text = Language.getString(69828);
            }
            this._progressBar.setValue(arg1.entityInfo.maxMana - arg1.entityInfo.mana, arg1.entityInfo.maxMana);
            this._operBtn.clearCountDown();
            if (this._isMine) 
            {
                if (this._isFlower) 
                {
                    this.title = Language.getString(69811);
                }
                else 
                {
                    this.title = Language.getString(69826);
                }
                this._operBtn.enabled = true;
                if (this._canGet) 
                {
                    this._operBtn.timeCount = 3;
                    this._operBtn.label = this._isFlower ? Language.getString(69822) : Language.getString(69833);
                    this._operBtn.toolTipData = "";
                }
                else 
                {
                    this._operBtn.timeCount = 60;
                    this._operBtn.label = Language.getString(69814);
                    if (this._isFlower) 
                    {
                        this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getString(69824), "#FFFFFF"));
                    }
                    else 
                    {
                        this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getString(69835), "#FFFFFF"));
                    }
                    loc1 = PlantFlowerBlessCache.getInviteCd();
                    if (loc1 > 0) 
                    {
                        this._operBtn.trigger();
                        this._operBtn.repeatCount = loc1;
                    }
                }
                this._itemsList.setItems(PlantFlowerConfig.instance.getPlantAward(arg1.entityInfo.code));
                this._tip.visible = false;
            }
            else 
            {
                this.title = Language.getString(69825);
                this._itemsList.setItems(PlantFlowerConfig.instance.getBlessAward(arg1.entityInfo.code));
                this._operBtn.timeCount = 3;
                this._operBtn.label = Language.getString(69815);
                if (this._isFlower) 
                {
                    this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getStringByParam(69823, this._itemsList.getItemNameByIndex(0), this._itemsList.getItemNameByIndex(1), this._itemsList.getItemNameByIndex(2)), "#FFFFFF"));
                }
                else 
                {
                    this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getStringByParam(69834, this._itemsList.getItemNameByIndex(0), this._itemsList.getItemNameByIndex(1), this._itemsList.getItemNameByIndex(2)), "#FFFFFF"));
                }
                this._tip.visible = true;
                this._tip.htmlText = HTMLUtil.addColor(Language.getStringByParam(69816, GameConst.PlantFlowerBlessRewardLimit), "#FFFF00") + HTMLUtil.addColor(" (" + Cache.instance.plantFlower.hasBlessTimes + "/" + GameConst.PlantFlowerBlessRewardLimit + ")", GlobalStyle.color5);
                if (this._canGet || PlantFlowerBlessCache.hasBless(arg1.entityInfo.entityId)) 
                {
                    this._operBtn.enabled = false;
                }
                else 
                {
                    this._operBtn.enabled = true;
                }
            }
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isMine) 
            {
                if (this._canGet) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_GetFlower, this._info));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_InviteBless, this._info));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_DoBless, this._info));
                this.hide();
            }
            return;
        }

        /* internal */ /* var */_isMine: Boolean;

        /* internal */ /* var */_canGet: Boolean;

        /* internal */ /* var */_info: EntityInfo;

        /* internal */ /* var */_bossInfo: TBoss;

        /* internal */ /* var */_isFlower: Boolean;

        /* internal */ /* var */_nameLabel: GTextFiled;

        /* internal */ /* var */_blessLable: GTextFiled;

        /* internal */ /* var */_itemsList: ItemsBox;

        /* internal */ /* var */_progressBar: RechargeProgressBar;

        /* internal */ /* var */_operBtn: TimeButton;

        /* internal */ /* var */_tip: FireTip;
    }
